/*
 * @Description: 主题配置
 * @Autor: 赖维健(lwj1994)
 * @Date: 2021-09-28 11:10:14
 * @LastEditors: 赖维健(lwj1994)
 * @LastEditTime: 2021-11-10 20:27:31
 */
import store from '@/store'

// 设置默认主题
export const setdefaultTheme = () => {
  const params = {
    name: '默认',
    code: 'default',
    options: {
      '--text-color': '#666',
      '--body-image': 'none',
      '--van-tabbar-item-background-color': 'red'
    },
  }

  store.commit('setDefaultTheme', params)
}

// 设置主题
export const setCurrentTheme = params => {
  // 没有选择主题，则使用当前激活的主题或默认主题
  if (params) store.commit('setActiveTheme', params)
  params = params || store.getters.activeTheme || store.getters.defaultTheme

  const rootElement = document.querySelector(':root')
  const options = params.options

  for (const k in options) {
    rootElement.style.setProperty(k, options[k])
  }
}
